﻿using MODEL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace StudentManage
{
    public partial class Frm_Update : Form
    {
        Frm_List frm_List = new Frm_List();
        public Frm_Update()
        {
            InitializeComponent();
        }
        DataGridView dgv_Update;
        public Frm_Update(DataGridView dgv_Update)
        {
            InitializeComponent();
            this.dgv_Update = dgv_Update;
        }

        ListBox listBox;
        public Frm_Update(ListBox listBox)
        {
            this.listBox = listBox;
            InitializeComponent();
        }

        private void btn_Update_Click(object sender, EventArgs e)
        {
            StuCard stuCard = new StuCard();

            stuCard.StuId = this.lbl_StuUser.Text;
            stuCard.StuName = this.txt_StuName.Text;
            stuCard.StuCardId = this.label5.Text;
            if (radioButton1.Checked == true)
            {
                stuCard.StuSex = radioButton1.Text;
            }
            else
            {
                stuCard.StuSex = radioButton2.Text;
            }
            try
            {

                //执行修改的方法
                int num = BLL.StuCardManage.StuCardService.Update(stuCard);
                if (num > 0)
                {
                    MessageBox.Show("操作成功");
                    this.Close();
                    dgv_Update.DataSource = BLL.StuCardManage.StuCardService.ChaXunStudent();
                   // listBox.Items.Add($"修改学号为：{dgv_Update.SelectedRows[0].Cells["StuId"].Value.ToString()} 的学生信息，操作成功");

                }
                else
                {
                    MessageBox.Show("操作失败");
                    //listBox.Items.Add($"修改学号为：{dgv_Update.SelectedRows[0].Cells["StuId"].Value.ToString()} 的学生信息，操作失败");
                }

            }
            catch (Exception ex)
            {

                //显示错误信息
                MessageBox.Show(ex.Message);
                //listBox.Items.Add("执行操作时出现问题:\t\n" + ex.Message);
            }

        }

        private void Frm_Update_Load(object sender, EventArgs e)
        {

            this.dgv_Update.DataSource = BLL.StuCardManage.StuCardService.ChaXunStudent();
            //选中行id
            this.lbl_StuUser.Text = dgv_Update.SelectedRows[0].Cells["StuId"].Value.ToString();
            //选中行姓名
            this.txt_StuName.Text = dgv_Update.SelectedRows[0].Cells["StuName"].Value.ToString();
            //选中行卡号
            this.label5.Text = dgv_Update.SelectedRows[0].Cells["StuCardID"].Value.ToString();

            if (dgv_Update.SelectedRows[0].Cells["StuName"].Value.ToString() == "男")
            {
                radioButton2.Checked = true;

            }
            else
            {
                radioButton1.Checked = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] data = new byte[12];
            if (HPITRFID.EPCSDKHelper.IdentifySingleTag(Frm_Main.handle, data, null, 0) == true)
            {
               
                this.label5.Text= HPITRFID.ConvertHelper.ByteArrayToHexString(data);
                MessageBox.Show("读取成功");
            }
            else
                //Frm_List.listBox1.Items.Add("读取失败");
                MessageBox.Show("读取失败");
        }
    }
}
